/**
 * 
 */
package org.hljdrl.daf.ft;

import java.util.Date;

import org.hljdrl.daf.R;
import org.hljdrl.daf.test.ModuleTest;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

/**
 * @author Administrator
 * 
 */
public class Fragment1 extends Fragment implements OnClickListener {

	private ModuleTest mModuleTest;

	public Fragment1() {
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	View rootView;
	private Button btn;
	private TextView body;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return inflater.inflate(R.layout.root_ft_1, container, Boolean.FALSE);
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		rootView = getView();
		btn = (Button) rootView.findViewById(R.id.ft_button1);
		btn.setOnClickListener(this);

		body = (TextView) rootView.findViewById(R.id.textView1);
		body.setText(message);
	}

	public ModuleTest getModuleTest() {
		return mModuleTest;
	}

	public void setModuleTest(ModuleTest mModuleTest) {
		this.mModuleTest = mModuleTest;
	}

	private boolean running = false;
	private String message="";
	@SuppressWarnings("deprecation")
	@Override
	public void onClick(View v) {
		if (!running) {
			running = true;
			body.setText("");
			StringBuffer mSm = new StringBuffer();
			mSm.append(new Date(System.currentTimeMillis()).toLocaleString());
			mSm.append("\n");
			mSm.append("runEncode:---------------\n");
			mSm.append("\n");
			mSm.append(mModuleTest.runEncode());
			mSm.append("\n");
			mSm.append("\n");
			mSm.append("runDecode:------------------\n");
			mSm.append(mModuleTest.runDecode());
			mSm.append("\n");
			message = mSm.toString();
			body.setText(message);
			running = false;

		}
	}

}
